package com.lfy.kcat.user.controller;

import com.lfy.kcat.user.business.DramaBizService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.dto.home.HomeDramaEpisodesDTO;
import org.dromara.common.core.dto.home.HomeDramaInfoDTO;
import org.dromara.common.core.dto.home.HomeFeaturedDTO;
import org.dromara.common.core.dto.PageReqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 首页功能
 * @author leifengyang
 * @version 1.0
 * @date 2025/9/17 10:20
 * @description:
 */
@RequestMapping("/api")
@RestController
public class AppHomeController {


    @Autowired
    DramaBizService  dramaBizService;

    //模拟本地缓存
    Map<String,HomeFeaturedDTO> cacheDb = new ConcurrentHashMap<>();

    @GetMapping("/hello")
    public R hello(){
        cacheDb.get("home:feature:1:15");

        //数据返回太多导致的
        return R.ok("hello");
    }

    /**
     * 获取首页精选短剧
     * @return
     */
    @GetMapping("/episodes/featured")
    public R feature(PageReqDTO pageReqVo){

        //获取所有数据
        HomeFeaturedDTO result = dramaBizService.getHomeFeature(pageReqVo);
        return R.ok(result);
    }


    /**
     * 获取短剧所有剧集
     * @param dramaId
     * @return
     */
    @GetMapping("/dramas/{dramaId}/episodes/all")
    public R dramaEpisodesInfo(@PathVariable("dramaId") Long dramaId){
        HomeDramaEpisodesDTO dto = dramaBizService
            .getDramaEpisodesInfo(dramaId);
        return R.ok(dto);
    }

    /**
     * 获取短剧基本信息
     */
    @GetMapping("/dramas/{dramaId}")
    public R<HomeDramaInfoDTO> dramaInfo(@PathVariable("dramaId") Long dramaId){
        HomeDramaInfoDTO dto = dramaBizService.getDramaInfo(dramaId);

        return R.ok(dto);
    }

}
